<template>
  <div>
    <ant-modal
      modalWidth="400"
      modalHeight="300"
      :visible="open"
      :modal-title="title"
      @cancel="cancel"
      :adjustSize="false"
    >
      <a-form-model
        ref="form"
        :model="form"
        :rules="rules"
        slot="content"
        layout="vertical"
      >
        <a-row>
          <a-col :span="24" style="margin-top: -15px">
            <a-tag
              color="#108ee9"
              v-for="(item, k) in toHeimingdanReasonOptions"
              :key="k"
              @click="handleReasonQuickInput(item.dictValue)"
              >{{ item.dictLabel }}</a-tag
            >
            <a-tooltip>
              <template slot="title">
                快捷输入可在系统设置-字典管理-拉黑原因添加
              </template>
              <a-icon type="question-circle" style="color: red" />
            </a-tooltip>
          </a-col>
          <a-col :span="24" style="margin-top: 10px">
            <a-textarea
              v-model="form.toHeimingdanReason"
              :auto-size="{ minRows: 5, maxRows: 5 }"
              allowClear
          /></a-col>
        </a-row>
      </a-form-model>
      <template slot="footer">
        <a-button @click="cancel"> 取消 </a-button>
        <a-button type="primary" @click="submit"> 确定 </a-button>
      </template>
    </ant-modal>
  </div>
</template>
<script>
import AntModal from "@/components/pt/dialog/AntModal";
export default {
  components: {
    AntModal,
  },
  props: {
    toHeimingdanReasonOptions: {
      type: Array,
      required: true,
    },
    title: {
      type: String,
      default: "选择",
    },
  },
  data() {
    return {
      open: false,
      form: { toHeimingdanReason: undefined },
      rules: {
        toHeimingdanReason: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    // 点击跟进快捷输入
    handleReasonQuickInput(text) {
      if (this.form.toHeimingdanReason) {
        this.form.toHeimingdanReason =
          this.form.toHeimingdanReason + " " + text;
      } else {
        this.form.toHeimingdanReason = text;
      }
      console.log("this.form.toHeimingdanReason", this.form.toHeimingdanReason);
    },
    showModal() {
      this.open = true;
      this.form = {
        toHeimingdanReason: undefined,
      };
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.$emit("close");
    },
    submit: function () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit("ok", this.form.toHeimingdanReason);
        } else {
          return false;
        }
      });
    },
  },
};
</script>
